<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas-cap</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <canvas id="tutorial" width="300" height="300">你的浏览器不支持 canvas，请升级你的浏览器。</canvas>
    <script>
        let lineCaps = ["butt", "round", "square"];
        let canvas = document.getElementById('tutorial');
        //获得 2d 上下文对象
        if (canvas.getContext) {
            let ctx = canvas.getContext('2d');
            for (var i = 0; i < 3; i++) {
                ctx.beginPath();
                ctx.moveTo(20 + 30 * i, 30);
                ctx.lineTo(20 + 30 * i, 100);
                ctx.lineWidth = 20;
                ctx.lineCap = lineCaps[i];
                ctx.stroke();
            }
        } else {
            console.log("您的浏览器不支持canvas!");
        }
        function randomInt(from, to) {
            return parseInt(Math.random() * (to - from + 1) + from);
        }
    </script>
</body>

</html>